<?php

/**
 * This is the model class for table "waktu".
 *
 * The followings are the available columns in table 'waktu':
 * @property integer $kode_wkt
 * @property string $kode_user
 * @property string $tgl_akses
 * @property string $jam_mulai
 * @property string $tgl_selesai
 * @property string $jam_selesai
 * @property string $sts
 *
 * The followings are the available model relations:
 * @property Users $kodeUser
 */
class Waktu extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'waktu';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('kode_user', 'length', 'max'=>8),
			array('sts', 'length', 'max'=>1),
			array('tgl_akses, jam_mulai, tgl_selesai, jam_selesai', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('kode_wkt, kode_user, tgl_akses, jam_mulai, tgl_selesai, jam_selesai, sts', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'kodeUser' => array(self::BELONGS_TO, 'Users', 'kode_user'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'kode_wkt' => 'Kode Wkt',
			'kode_user' => 'Kode User',
			'tgl_akses' => 'Tgl Akses',
			'jam_mulai' => 'Jam Mulai',
			'tgl_selesai' => 'Tgl Selesai',
			'jam_selesai' => 'Jam Selesai',
			'sts' => 'Sts',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('kode_wkt',$this->kode_wkt);
		$criteria->compare('kode_user',$this->kode_user,true);
		$criteria->compare('tgl_akses',$this->tgl_akses,true);
		$criteria->compare('jam_mulai',$this->jam_mulai,true);
		$criteria->compare('tgl_selesai',$this->tgl_selesai,true);
		$criteria->compare('jam_selesai',$this->jam_selesai,true);
		$criteria->compare('sts',$this->sts,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Waktu the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
